When the player 'catches' a piece of information, let's remove that hit_sprite from the stage.
A hit_sprite is what we call the info sprites inside the collision event.
Go to and drag out Remove Sprite . Drop it inside the collision event. Change sprite in .remove_sprite() to hit_sprite .
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background("schoolhallway")
sprite = codesters.Sprite("person8")
stage.set_gravity(4)
stage.disable_floor()
sprite.set_gravity_off()
sprite.go_to(0, -220)
score = 0
score_board = codesters.Display(score)
my_info = ["cellphone", "address", "birthdate"]
def left_key():
sprite.move_left(20)
# add other actions...
stage.event_key("left", left_key)
def right_key():
sprite.move_right(20)
# add other actions...
stage.event_key("right", right_key)
def interval():
x = random.randint(-230, 230)
info_img = random.choice(my_info)
# sprite = codesters.Sprite("image", x, y)
info = codesters.Sprite(info_img, x, 275)
# add any other actions...
stage.event_interval(interval, 3)
def collision(sprite, hit_sprite):
# add any other actions...
global score
sprite.event_collision(collision)
t = codesters.Teacher()
try:
tval1 = t.get_indent_at_line(t.find_function('remove_sprite')[0][0])
tval2 = t.get_parameters_for_function('remove_sprite')[0][0]
except:
tval1 = "DNE"
tval2 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == 4 and tval2 == 'hit_sprite', "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Remove Sprite command?")
t1.add_failure(tval2 != "hit_sprite", "Did you change the name in the Remove Sprite command to hit_sprite?")
t1.add_failure(tval1 < 4, "Make sure your Remove Sprite command is indented inside your collision event.")
t1.add_failure(tval1 > 4, "Make sure your Remove Sprite command is only indented 4 spaces inside the Collision Event!")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
Run Code
Activity Submitted!
Submit Work
Next Activity
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)